home *** CD-ROM | disk | FTP | other *** search
- // NoSound
- // Created 3/1/92
- // Faustino Forcén
-
- #include "Finder.h"
- #include "shutdown.h"
- #include "script.h"
-
- int lee()
- {
- int elValor;
- FSSpec spec;
- long elCount;
- long foundDir;
- short vRef;
- OSErr elError;
- Str255 nombredisco="\pNoSound.prefs";
- int refNum;
-
- elError = FindFolder(kOnSystemDisk, 'pref', kDontCreateFolder,&vRef, &foundDir);
- // another bendition from sys 7 or "How to find your way home in a drunky night"
- if (elError == noErr)
- {
- FSMakeFSSpec(vRef, foundDir, nombredisco, &spec); // the brand new calls from sys 7
- elError = FSpOpenDF(&spec, fsRdWrPerm, &refNum);
- if (elError != noErr) // we failed…
- return(3); // default value
- elCount = 2L;
- FSRead(refNum, &elCount,&elValor);
- FSClose(refNum);
- if(elCount==0) // file is empty
- elValor=3; // default value
- }
- else
- elValor=3;
- return(elValor);
- }
-
- pascal void shut_down()
- {
- int refNum;
- int valor;
- SysPPtr elPuntero;
- FSSpec spec;
- long elCount;
- long foundDir;
- OSErr elError;
- short vRef;
- Str255 nombredisco;
-
-
- // we haven´t globals at this time, so…
- nombredisco[0]=13;
- nombredisco[1]='N';
- nombredisco[2]='o';
- nombredisco[3]='S';
- nombredisco[4]='o';
- nombredisco[5]='u';
- nombredisco[6]='n';
- nombredisco[7]='d';
- nombredisco[8]='.';
- nombredisco[9]='p';
- nombredisco[10]='r';
- nombredisco[11]='e';
- nombredisco[12]='f';
- nombredisco[13]='s';
- // yes, is really dirty, but it works
-
- InitUtil(); // from the PRAM calls
- elPuntero=GetSysPPtr();
- valor = ((elPuntero->volClik & 0x0700) >> 8);
- elError = FindFolder(kOnSystemDisk, 'pref', kDontCreateFolder, &vRef, &foundDir);
- if (elError == noErr)
- {
- FSMakeFSSpec(vRef, foundDir, nombredisco, &spec);
- elError = FSpOpenDF(&spec, fsRdWrPerm, &refNum);
- if (elError == fnfErr) // this is also your first time, baby?
- {
- FSpCreate(&spec, 'SARA', 'VOL ', smSystemScript);
- // yes, my daughter calls SARA, how you guess it?
- FSpOpenDF(&spec, fsRdWrPerm, &refNum);
- }
- elCount = 2L;
- FSWrite(refNum, &elCount, &valor);
- FSClose(refNum);
- }
- // here´s the real stuff, when we change the vol
- elPuntero->volClik = (elPuntero->volClik & 0xf8ff) + (1 << 8);
- WriteParam();
- }
-
- void main(void)
- {
- long size;
- Ptr puntero,otro, temp;
- char buffer[4];
- int refNum;
- int volumen;
- SysPPtr elPuntero;
-
- volumen=lee(); // we want to get the original volume, stored somewhere
- InitUtil();
- elPuntero=GetSysPPtr();
- // we put the vol to the original value
- // in the worst case (no file, some error) it will be 3 (default value)
- elPuntero->volClik = (elPuntero->volClik & 0xf8ff) + (volumen << 8);
- WriteParam();
- // now tell the Mac that we changed its mind
- SetSoundVol(volumen);
-
- // now began the install process
- size = (long) ((Ptr) ApplLimit - (Ptr) ApplZone);
- puntero = NewPtrSysClear(size);
- if (puntero)
- {
- temp = (Ptr) shut_down;
- buffer[0] = *(temp+2);
- buffer[1] = *(temp+3);
- buffer[2] = *(temp+4);
- buffer[3] = *(temp+5);
- BlockMove(ApplZone,puntero,size);
- otro = (Ptr) (long) puntero + (*(long *)buffer - (long) ApplZone);
- ShutDwnInstall((ProcPtr)otro, sdRestartOrPower + sdOnUnmount + sdOnDrivers);
- }
- ExitToShell();
- // we need to assure that our proc is linked with the app
- shut_down();
- }
-
- // eof
-